<?php

abstract class factory{
	abstract protected  function  todo();
}


class _Factory extends factory {
	private $fid;
	private $action;
	private $_act;
	private $_mod;
	private $_template;
	
	private $runAct;
	
	public function __construct($fid){
		$this->fid = $fid;
		$const = null;
		$this->find = false;
//		if(count($_POST)>0){
//			$const = &$_POST;
//		}else{
//			$const = &$_GET;
//		}
		$const = &$_REQUEST;
		foreach($const as $key=>$value){
			if(is_numeric($key))continue;
			if($key==_cfg::command){
				$this->_act=$value;
				$this->find = true;
				continue;
			}
			if($key==_cfg::model){
				$this->_mod=$value;
				continue;
			}
		}
	}
	
	public function constat(&$adt){
		$this->loadApp(&$adt);
	}
	
	/**
	 * 载入应用	 *
	 */
	private function loadApp(&$adt){
		if(!in_array($this->_act,$this->action->get('actionsName')))$this->_act = $this->action->get('defaultAction');
		$this->runAct = $this->action->get('actions');
		$_action = $this->runAct[$this->_act]['action'];
		$importClass = $this->runAct[$this->_act]['classpath'];
		$instclass = $this->runAct[$this->_act]['instclass'];
		$modcomment = $this->runAct[$this->_act]['comment'];
		_importClass($importClass);
		eval("\$appobj = new $instclass();");
		$mos = null;
		$modName = "def";	//默认响应方法
		$tempObj = $this->runAct[$this->_act];
		if(!empty($this->_mod)){
			$modName = trim($this->_mod);
			eval("\$mos = \$tempObj['model']->$modName;");
		}
		else{
			eval("\$mos = \$tempObj['model']->def;");
		}
		//print_r($mos);
		$appobj->setTemplate((string)$mos->template);	//模板文件
		$appobj->setClass($instclass);
		$appobj->setMethod((string)$mos->mod);
		$appobj->setAppName($modcomment);
		$appobj->setModName($modName);
		$adt->setApp(&$appobj);
	}
	
	public function appAction($param){
		$this->action = &$param;
	}
	
	public function todo(){
		
	}
}

return md5(__FILE__);